package com.admin.controller;

import com.admin.service.ApplyService;
import com.admin.entity.Apply;
import com.admin.sys.base.module.extend.web.BaseController;
import com.admin.sys.base.entity.ResultInfo;
import com.admin.sys.utils.admin.ShiroUtils;
import com.admin.sys.utils.admin.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
*【预约信息】页面接口
*/
@RestController
@RequestMapping("/admin/apply")
public class ApplyController extends BaseController {

    @Autowired
    private ApplyService applyService;

    /**
    * 【预约信息】根据条件分页查询
    * @param page
    * @param apply
    * @return
    */
    @RequestMapping("/getPage")
    public ResultInfo getPage(Page<Apply> page, Apply apply) {
        //角色数据过滤
        if (ShiroUtils.getUserRole().contains("doctorRole")) {
            apply.setUserId(ShiroUtils.getUserInfo().getId());
        }
        IPage<Apply> iPage = applyService.getPage(page, apply);
        return ResultInfo.ok("获取分页成功", iPage);
    }

    /**
    * 【预约信息】根据条件查询
    * @param apply
    * @return
    */
    @RequestMapping("/getList")
    public ResultInfo getList(Apply apply) {
        List<Apply> list = applyService.getList(apply);
        return ResultInfo.ok("获取列表成功", list);
    }

    /**
    * 【预约信息】根据对象查询
    * @param apply
    * @return
    */
    @RequestMapping("/get")
    public ResultInfo get(Apply apply) {
        Apply entity = applyService.get(apply);
        return ResultInfo.ok("获取对象成功", entity);
    }

    /**
    * 【预约信息】提交(新增或修改)
    * @param apply
    * @return
    */
    @RequestMapping("/sub")
    public ResultInfo insert(Apply apply) {
        if (StringUtils.isEmpty(apply.getId())) { //新增
            applyService.insert(apply);
        } else {//修改
            applyService.update(apply);
        }
        return ResultInfo.ok("提交成功!");
    }

    /**
    * 【预约信息】删除
    * @param id
    * @return
    */
    @RequestMapping("/delete")
    public ResultInfo delete(String id) {
        applyService.delete(id);
        return ResultInfo.ok("删除成功!");
    }

    /**
    * 【预约信息】批量删除
    * @param ids
    * @return
    */
    @RequestMapping("/delAll")
    public ResultInfo delAll(String[] ids) {
        applyService.delAll(ids);
        return ResultInfo.ok("批量删除成功！");
    }



}



